#include"fufu.h"

fufu::fufu(){
    runimg.load(RUN_PATH);   //fufu图片加载
    jumpimg.load(JUMP_PATH);

    jumptimer.setInterval(JUMPTIME);
    jumptimer.setSingleShot(true);

    downspeed=DOWNSPEED;  //跳跃
    jump1=false;
    jump2=false;

    fufurect.setWidth(51);        //初始化角色边框
    fufurect.setHeight(102);
    fufurect.moveTo(x+17,y+8);
}


QPixmap fufu::getImg(){              //根据位置获取角色状态图片
    if(y>=FUFU_ONGROUND_Y){
        return runimg;
    }
    else return jumpimg;
}

void fufu::jump(){
    if(y==FUFU_ONGROUND_Y){
        jump1=false;
        jump2=false;
        downspeed=DOWNSPEED;
    }
    if(jump2||(jumptimer.remainingTime()>200&&jumptimer.isActive())){
        return;
    }
    if(y==FUFU_ONGROUND_Y){
        jumptimer.start();
        jump1=true;
    }
    if(y<FUFU_ONGROUND_Y&&!jump2){
        jumptimer.start();
        jump2=true;
    }
}

void fufu::updateY(){
    if(jumptimer.isActive()){
        y-=jumptimer.remainingTime()/45;
    }
    else{
        downspeed+=0.03;              //下落加速度
        y+=downspeed;
    }
    if(y>=FUFU_ONGROUND_Y){
        y=FUFU_ONGROUND_Y;
    }
    fufurect.moveTo(x+17,y+8);
}
